using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQFKLASSE
    {
        public DataRow Convert2QFKLASSE(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQFKLASSE(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["QFKMANDANT"] = " ".PadRight(2 ); 
         dwReturn["QFKGKREGEL"] = " ".PadRight(8 ); 
         dwReturn["QFKFKATALOG"] = " ".PadRight(3 ); 
         dwReturn["QFKFSCHL"] = " ".PadRight(3 ); 
         dwReturn["QFKFGRP"] = " ".PadRight(3 ); 
         dwReturn["QFKBISLG"] = " ".PadRight(6 ); 
         dwReturn["QFKMEEHLG"] = " ".PadRight(1 ); 
         dwReturn["QFKBISBRT"] = " ".PadRight(6 ); 
         dwReturn["QFKMEEHBRT"] = " ".PadRight(1 ); 
         dwReturn["QFKAENZL"] = " ".PadRight(0 ); 
         dwReturn["QFKAENB"] = " ".PadRight(8 ); 
         dwReturn["QFKAEND"] = " ".PadRight(0 ); 
         dwReturn["QFKNEUB"] = " ".PadRight(8 ); 
         dwReturn["QFKNEUD"] = " ".PadRight(0 ); 
         dwReturn["QFKSTATUS"] = " ".PadRight(1 ); 
         dwReturn["QFKPKTF"] = " ".PadRight(1 ); 
         dwReturn["QFKVGUETVAR"] = " ".PadRight(0 ); 
         dwReturn["QFKVGUETFIX"] = " ".PadRight(0 ); 
         dwReturn["QFKFPKT"] = " ".PadRight(0 ); 
         dwReturn["QFKMSCHN"] = " ".PadRight(1 ); 
         dwReturn["QFKMSCHNAB"] = " ".PadRight(0 ); 
         dwReturn["QFKRAND"] = " ".PadRight(1 ); 
         dwReturn["QFKMELD"] = " ".PadRight(1 ); 
         dwReturn["QFKREPBAR"] = " ".PadRight(1 ); 
         dwReturn["QFKREPKOST"] = " ".PadRight(0 ); 
         dwReturn["QFKWE"] = " ".PadRight(3 ); 
         dwReturn["QFKREPDAUER"] = " ".PadRight(0 ); 
         dwReturn["QFKREPDAUERF"] = " ".PadRight(1 ); 
         dwReturn["QFKFILLER"] = " ".PadRight(31 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQFKLASSE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQFKLASSE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQFKLASSE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQFKLASSE(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQFKLASSE(dwLocal, ITXDBVERSION);
            }
            UpdateQFKLASSE(dwLocal);
        }
        public void InsertQFKLASSE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QFKLASSE(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQFKLASSE(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QFKLASSE WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QFKLASSE  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QFKLASSE";
            Return = Result;
            return Return;
        }
        public void DeleteQFKLASSE(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QFKLASSE   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQFKLASSE(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QFKLASSE SET "
                    +"QFKMANDANT= :QFKMANDANT,"
                    +"QFKGKREGEL= :QFKGKREGEL,"
                    +"QFKFKATALOG= :QFKFKATALOG,"
                    +"QFKFSCHL= :QFKFSCHL,"
                    +"QFKFGRP= :QFKFGRP,"
                    +"QFKBISLG= :QFKBISLG,"
                    +"QFKMEEHLG= :QFKMEEHLG,"
                    +"QFKBISBRT= :QFKBISBRT,"
                    +"QFKMEEHBRT= :QFKMEEHBRT,"
                    +"QFKAENZL= :QFKAENZL,"
                    +"QFKAENB= :QFKAENB,"
                    +"QFKAEND= :QFKAEND,"
                    +"QFKNEUB= :QFKNEUB,"
                    +"QFKNEUD= :QFKNEUD,"
                    +"QFKSTATUS= :QFKSTATUS,"
                    +"QFKPKTF= :QFKPKTF,"
                    +"QFKVGUETVAR= :QFKVGUETVAR,"
                    +"QFKVGUETFIX= :QFKVGUETFIX,"
                    +"QFKFPKT= :QFKFPKT,"
                    +"QFKMSCHN= :QFKMSCHN,"
                    +"QFKMSCHNAB= :QFKMSCHNAB,"
                    +"QFKRAND= :QFKRAND,"
                    +"QFKMELD= :QFKMELD,"
                    +"QFKREPBAR= :QFKREPBAR,"
                    +"QFKREPKOST= :QFKREPKOST,"
                    +"QFKWE= :QFKWE,"
                    +"QFKREPDAUER= :QFKREPDAUER,"
                    +"QFKREPDAUERF= :QFKREPDAUERF,"
                    +"QFKFILLER= :QFKFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("QFKMANDANT", OracleType.NVarChar).Value = dwData["QFKMANDANT"].ToString(); 
          or1.Parameters.Add("QFKGKREGEL", OracleType.NVarChar).Value = dwData["QFKGKREGEL"].ToString(); 
          or1.Parameters.Add("QFKFKATALOG", OracleType.NVarChar).Value = dwData["QFKFKATALOG"].ToString(); 
          or1.Parameters.Add("QFKFSCHL", OracleType.NVarChar).Value = dwData["QFKFSCHL"].ToString(); 
          or1.Parameters.Add("QFKFGRP", OracleType.NVarChar).Value = dwData["QFKFGRP"].ToString(); 
          or1.Parameters.Add("QFKBISLG", OracleType.NVarChar).Value = dwData["QFKBISLG"].ToString(); 
          or1.Parameters.Add("QFKMEEHLG", OracleType.NVarChar).Value = dwData["QFKMEEHLG"].ToString(); 
          or1.Parameters.Add("QFKBISBRT", OracleType.NVarChar).Value = dwData["QFKBISBRT"].ToString(); 
          or1.Parameters.Add("QFKMEEHBRT", OracleType.NVarChar).Value = dwData["QFKMEEHBRT"].ToString(); 
          or1.Parameters.Add("QFKAENZL", OracleType.NVarChar).Value = dwData["QFKAENZL"].ToString(); 
          or1.Parameters.Add("QFKAENB", OracleType.NVarChar).Value = dwData["QFKAENB"].ToString(); 
          or1.Parameters.Add("QFKAEND", OracleType.NVarChar).Value = dwData["QFKAEND"].ToString(); 
          or1.Parameters.Add("QFKNEUB", OracleType.NVarChar).Value = dwData["QFKNEUB"].ToString(); 
          or1.Parameters.Add("QFKNEUD", OracleType.NVarChar).Value = dwData["QFKNEUD"].ToString(); 
          or1.Parameters.Add("QFKSTATUS", OracleType.NVarChar).Value = dwData["QFKSTATUS"].ToString(); 
          or1.Parameters.Add("QFKPKTF", OracleType.NVarChar).Value = dwData["QFKPKTF"].ToString(); 
          or1.Parameters.Add("QFKVGUETVAR", OracleType.NVarChar).Value = dwData["QFKVGUETVAR"].ToString(); 
          or1.Parameters.Add("QFKVGUETFIX", OracleType.NVarChar).Value = dwData["QFKVGUETFIX"].ToString(); 
          or1.Parameters.Add("QFKFPKT", OracleType.NVarChar).Value = dwData["QFKFPKT"].ToString(); 
          or1.Parameters.Add("QFKMSCHN", OracleType.NVarChar).Value = dwData["QFKMSCHN"].ToString(); 
          or1.Parameters.Add("QFKMSCHNAB", OracleType.NVarChar).Value = dwData["QFKMSCHNAB"].ToString(); 
          or1.Parameters.Add("QFKRAND", OracleType.NVarChar).Value = dwData["QFKRAND"].ToString(); 
          or1.Parameters.Add("QFKMELD", OracleType.NVarChar).Value = dwData["QFKMELD"].ToString(); 
          or1.Parameters.Add("QFKREPBAR", OracleType.NVarChar).Value = dwData["QFKREPBAR"].ToString(); 
          or1.Parameters.Add("QFKREPKOST", OracleType.NVarChar).Value = dwData["QFKREPKOST"].ToString(); 
          or1.Parameters.Add("QFKWE", OracleType.NVarChar).Value = dwData["QFKWE"].ToString(); 
          or1.Parameters.Add("QFKREPDAUER", OracleType.NVarChar).Value = dwData["QFKREPDAUER"].ToString(); 
          or1.Parameters.Add("QFKREPDAUERF", OracleType.NVarChar).Value = dwData["QFKREPDAUERF"].ToString(); 
          or1.Parameters.Add("QFKFILLER", OracleType.NVarChar).Value = dwData["QFKFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
